<div class="admin-submenu">
    <div style="width: 100%; height: 100%">

        <div class="submenu-scene">
            文章管理
        </div>

        <div class="submenu-item">文章管理</div>

        <ul>
            <li><a href="/article"> 文章管理</a></li>
            <li><a href="/article/add">添加文章</a></li>
            <li class="active"><a href="/article/category">添加标签</a></li>
        </ul>

        <div id="admin-submenu-c">
            <i class="layui-icon layui-icon-prev"></i>
        </div>

    </div>

</div>
<div class="admin-content">
    <div class="layui-row layui-col-space30">
        <div class="layui-col-md12">
            <div class="adminpageheader">
                <h2 class="adminpagetitle">当前位置：<a href="">分类管理</a></h2>
            </div>
            <div class="admin-block">
                <div class="block">
                    <div class="example">
                        <form class="layui-form" action="" method="post" lay-filter="component-form-element">
                            <div class="layui-form-item">
                                <label class="layui-form-label">标签名：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" required lay-verify="required" placeholder="请输入标签名"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">英文标识：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="key" required lay-verify="required" placeholder="请输入英文标识"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <h1 class="heading-mi">标签列表</h1>
                    <table class="layui-table" lay-size="lg">
                        <colgroup>
                            <col width="150">
                            <col width="150">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>名称</th>
                            <th>标识</th>
                        </tr>
                        </thead>
                        <tbody>
                        {{range .list}}
                        <tr>
                            <td>{{.Name}}</td>
                            <td>{{.Key}}</td>
                        </tr>
                        {{end}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form'], function () {
        // 操作对象
        var $ = layui.jquery
                , layer = layui.layer
                , form = layui.form;
        form.on('submit(submit)', function (data) {
            $.post("/api/category/add", data.field, function (res) {
                if (res.Error === 0) {
                    layer.open({
                        title: res.Title
                        , content: res.Msg,
                        yes: function (index) {
                            window.location.href = "/article/category";
                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                        }
                    });
                } else {
                    layer.msg(res.Title + res.Msg, {time: 2000});
                }
            }, "json");
            return false;
        })
    });
</script>